//
//  MainView.m
//  4.7
//
//  Created by 王奎卿 on 2017/4/7.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "MainView.h"
#import "MainCell.h"

@implementation MainView

- (instancetype)initWithFrame:(CGRect)frame
{
    CGSize size = [UIScreen mainScreen].bounds.size;
    if (self = [super initWithFrame:CGRectMake(size.width-155, 70, 150, 150)])
    {
        [self showView];
    }
    return self;
}

- (void)showView
{
    self.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:self.tableView];
    
    self.array = [NSMutableArray arrayWithObjects:@"客户设置",@"客户分类",@"新增客户", nil];
    
//    UITabBarItem *item1 =  [[UITabBarItem alloc] initWithTitle:@"客户设置" image:[UIImage imageNamed:@""] tag:1];
//    UITabBarItem *item2 =  [[UITabBarItem alloc] initWithTitle:@"客户分类" image:[UIImage imageNamed:@""] tag:1];
//    UITabBarItem *item3 =  [[UITabBarItem alloc] initWithTitle:@"新增客户" image:[UIImage imageNamed:@""] tag:1];
//    self.tabBar.items = @[item1,item2,item3];
//    [self addSubview:self.tabBar];
//    self.tabBar.hidden = YES;
}

//- (UITabBar *)tabBar
//{
//    if (!_tabBar)
//    {
//        _tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0,0,150,100)];
//    }
//    return _tabBar;
//}


- (UITableView *)tableView
{
    if (!_tableView)
    {
        CGSize size = [UIScreen mainScreen].bounds.size;
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 150, 150)];
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
    }
    return _tableView;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseID = @"20170407";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];

    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseID];
    }
    cell.textLabel.text = self.array[indexPath.row];
    cell.textLabel.textColor = [UIColor blackColor];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        NSLog(@"点击第一单元格");
    }
    else if (indexPath.row == 1)
    {
        NSLog(@"点击第二单元格");
    }
    else if (indexPath.row == 2)
    {
        NSLog(@"点击第三单元格");
    }
}

@end
